<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <title>账号设置-修改邮箱 - EasyBlog博客</title>
    <th:block th:replace="~{ fragment/common::common_head}" />
</head>
<body>

<!--导航-->
<div th:replace="~{fragment/nav :: navbar}"></div>


<!--中间内容-->
<div class="m-content-container">
    <div class="ui stackable grid">
        <div class="one wide column"></div>
        <!--左侧菜单栏-->
        <div th:replace="~{ fragment/account-setting-sidebar::sidebar}"></div>
        <!--博客内容-->
        <div class="twelve wide column">
            <div class="ui top attached segment stackable">
                <h3 class="m-margin-top m-margin-bottom m-margin-left"
                    style="font-size: 20px !important;color: #3d3d3d !important;">
                    修改邮箱</h3>
                <div class="ui divider"></div>
                <div th:if="${user.getUserMail()!=null}" class="m-margin-left-large">
                    <div>
                        <span>验证码将会被发送到<span style="color: grey">[[${user.getUserMail()}]]</span>邮箱</span><br/>
                    </div>
                    <br/>
                    <div class="ui action  fluid input" style="width: 60% !important;">
                        <span class="m-margin-top">填写验证码：</span>
                        <input id="code" type="text">
                        <input id="email" type="hidden" th:value="${user.getUserMail()}">
                        <button id="sendCode"  class="ui blue mini button">获取验证码</button>
                    </div>
                    <br/>
                    <br/>
                    <button id="firm_btn" class="ui red medium disabled button m-margin-left-middle">
                        下一步
                    </button>

                </div>
                <div class="m-margin-left-large" th:if="${user.getUserMail()==null}">
                    <div style="margin:5em 5em 5em 10em">
                        <div style="margin-bottom: 2.5em !important;color: grey !important;font-size: 14px !important;">
                            你还没有绑定邮箱
                        </div>
                        <a href="#" th:href="@{/manage/account/bindEmailPage(userId=${user.getUserId()})}">
                            <button class="red  ui button">立即绑定邮箱</button>
                        </a>
                    </div>
                </div>
                <div style="padding-bottom: 12em !important;"></div>
            </div>
        </div>
    </div>
</div>
<div  class="ui small modal">
    <div class="header" id="msg_header">删除</div>
    <div id="msg" class="content">
    </div>
    <div class="actions">
        <div id="msg-btn" class="ui red button">知道了</div>
    </div>
</div>

<div style="height: 10em"></div>
<!--底部footer-->
<div th:replace="~{ fragment/common :: footbar}"></div>
</body>

<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>
<script src="../../../static/js/easyblog.js" th:src="@{/static/js/easyblog.js}"></script>
<script>
    $(document).ready(function () {
        let userId=$('#userId').val();
        showPageZoomWarning();
        toggleStatus();
        logOut();
    });
</script>
<script>
    $('#msg-btn').click(function () {
        $('.ui.modal').modal('hide');
    });

    let userId="[[${user.getUserId()}]]";
    $('#firm_btn').click(function () {
        $.ajax({
            url: "/manage/account/reset/email/next",
            method: 'GET',
            sync: true,
            data: {code: $('#code').val(),userId:userId},
            dataType: "json",
            success: function (response) {
                if (response.success) {
                  window.location.href="/manage/account/reset/email/nextPage?userId="+userId;
                } else {
                    spop({
                        template: response.message,
                        autoclose: 4000,
                        position: "top-center",
                        style: 'error',
                    });
                }
            },
            error: function () {
                spop({
                    template: '服务异常，请重试！',
                    autoclose: 4000,
                    position: "top-center",
                    style: 'error',
                });
            }
        });
    })
</script>
<script th:online="javascript">
    //60s倒计时
    var countdown=60;        //初始值
    function settime() {
        if (countdown == 0) {
            $('#sendCode').removeClass("disabled");
            $('#sendCode').html("获取验证码");
            countdown = 60;
            return false;
        } else {
            $('#sendCode').addClass("disabled");
            $('#sendCode').html("重新发送(" + countdown + ")");
            countdown--;
        }
        setTimeout('settime()',1000);
    };

    $('#sendCode').click(function () {
        $.ajax({
            url: "/manage/account/sendByEmail",
            method: 'GET',
            sync: true,
            data: {email: $('#email').val(),userId:userId},
            dataType: "json",
            success: function (response) {
                if (response.success) {
                    settime();
                    spop({
                        template: '邮件发送成功，请注意查收',
                        autoclose: 4000,
                        position: "top-right",
                        style: 'success',
                    });
                } else {
                    spop({
                        template: '抱歉！邮件发送失败，请稍后重试！',
                        autoclose: 4000,
                        position: "top-center",
                        style: 'error',
                    });
                }
            },
            error: function () {
                spop({
                    template: '服务异常，请重试！',
                    autoclose: 4000,
                    position: "top-center",
                    style: 'error',
                });
            }
        });
    });

</script>

<script>
    $('#account3').css("background", '#ca0c16');
    $('#account3').css('color', '#ffffff')
</script>
<!--控制按钮的禁用和可用状态-->
<script type="text/javascript">
    $(function () {
        function changePwd() {
            var len1 = document.getElementById("code").value.length;
            if (len1 != 0) {
                $('#firm_btn').removeClass("disabled");
            } else {
                $('#firm_btn').addClass("disabled");
            }
        }

        setInterval(changePwd, 300);
    });

</script>

<script>
    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });

    $('.ui.dropdown').dropdown({
        on: 'hover'
    });

    $('#searchBar').click(function () {
        $('#reloadSearchBar').css("display", "block");  //显示div
    })

</script>
</html>